<template>
	<view class="container">
	    <view class="address-list">
	      <!-- <view class="a-address"  v-for="(itme,index) in addressList" :key="index"> -->
	      <!-- <view class="left-text" :class="item.isDefault? 'active':''"> -->
				<view class="a-address" v-for="(itme,index) in addressList" :key="index">
						<view class="left-text active" @click="select(itme)">
								<view class="name-tel">
									{{itme.name}} {{itme.mobile}}
									<!-- <text class="is_default" v-if="true">默认地址</text> -->
								</view>
								<view class="address-box">
									{{itme.province}}{{itme.city}}{{itme.detail}}
								</view>
						</view>
						<view class="right-edit" @click="edit(itme.id)"></view> 
				</view>
	    </view>
	    <view class="bottom-box">
	        <view class="add-btn" @click="addAddess">新增收货地址</view>
	    </view>
	</view>
</template>

<script>
	import API from '@/common/api';
	export default {
		data(){
			return{
				addressList:[],	
				addres:'',
				sta:0,//选择地址
				
				userid:uni.getStorageSync("userid"),
			}
		},
		onLoad:function(e){
			this.sta = e.sta;
		},
		onShow:function(){
			// this.address_lists();
			this.mallAddress_list();
		},
		methods:{
			mallAddress_list(){
				var _this=this;
				uni.request({
					url:API.mallAddress_list,
					method:"GET",
					data:{userid:_this.userid},
					header:API.get_head(),
					success: (res) => {
						_this.addressList=res.data.rows;
					},
					fail: () => {
						uni.showToast({
							title:"加载失败",
							icon:'none'
						})
					 }
				})
			},
			select:function(e){
				if(this.sta==1){
					var _this=this;
					uni.request({
						url:API.setDefaultAddress,
						method:"GET",
						data:{userid:_this.userid,address_id:e.id},
						header:API.get_head(),
						success: (res) => {
							uni.navigateBack({
								delta:1,
							});
						},
						fail: () => {
							uni.showToast({
								title:"加载失败",
								icon:'none'
							})
						 }
					})
				}
			},
			

			addAddess:function(){
				uni.navigateTo({
					url:"./address-add",
				})
			},
			edit:function(id){
				uni.navigateTo({
					url:'address-add?id='+id,
				})
			},
			
		}
	}
</script>

<style>
.container {
    background-color:#F2f2f2;
}
.address-list{
    width: 100%;
    background-color: #fff;
    margin-top: 20upx;
}
.address-list .a-address{
    width: 720upx;
    margin-left: 30upx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 30upx 0;
    border-bottom: 1upx solid #eee;
}
.a-address .left-text{
    width: 610upx;
    box-sizing: border-box;
    /* padding-left: 58upx; */
}
.a-address .left-text.active{
/*    background: url(https://cdn.it120.cc/images/weappshop/addr-active.png) no-repeat left center;
    background-size: 28upx auto; */
}
.a-address .left-text .name-tel{
    margin-bottom: 20upx;
}
.a-address .left-text .address-box{
    font-size:24upx;
    color:#888888;
    line-height:36upx;
}
.a-address .right-edit{
    width: 109upx;
    height: 100%;
    padding: 50upx 0 50upx 58upx;
    box-sizing: border-box;
    background: url(https://cdn.it120.cc/images/weappshop/addr-edit.png) no-repeat 43upx center;
    background-size: 35upx auto;
}
.bottom-box{
    position: fixed;
    width: 100%;
    bottom: 0;
    font-size:28upx;
    color:#000000;
    border-top: 1upx solid #eee;
    height:100upx;
    line-height: 100upx;
    background-color: #fff;
    background: url(https://cdn.it120.cc/images/weappshop/arrow-right.png) no-repeat 705upx center;
    background-size: 15upx auto;
}
.bottom-box .add-btn{
    margin-left: 30upx;
	line-height:100upx;
    padding-left: 70upx;
    background: url(https://cdn.it120.cc/images/weappshop/add-addr.png) no-repeat left center;
    background-size: 40upx auto;
}
.is_default{
	font-size:24upx;
	color:red;
}	
</style>
